/**
 * 
 */
package gpl.scotlandyard.beans;

import gpl.scotlandyard.beans.basics.Link;
import gpl.scotlandyard.beans.basics.Node;
import gpl.scotlandyard.utils.Point;

import java.util.Comparator;
import java.util.List;

/** Reproduces node behavior with a additional information that is mark. Mark gives a natural order to nodes biggest mark
 * is first.
 * @author norbert */
public class MarkedNode {

  public static final int HOPEFULLY_MARK = 1;

  public static final int NEUTRAL_MARK = 0;

  public static final int HOPELESS_MARK = -1;

  public static final int IMPOSSIBLE_MARK = -100;

  private static final Comparator<MarkedNode> MARK_COMPARATOR = new Comparator<MarkedNode>() {
    @Override
    public int compare(MarkedNode o1, MarkedNode o2) {
      if (o1.mark == o2.mark) {
        return o1.getNumber() - o2.getNumber();
      }
      return o2.mark - o1.mark;
    }
  };

  private static final Comparator<MarkedNode> NUMBER_COMPARATOR = new Comparator<MarkedNode>() {
    @Override
    public int compare(MarkedNode o1, MarkedNode o2) {
      return o1.getNumber() - o2.getNumber();
    }
  };

  private final Node node;

  private int mark;

  /** Creates node with neutral mark. */
  public MarkedNode(Node node) {
    this.node = node;
    mark = NEUTRAL_MARK;
  }

  /** @return the mark */
  public int getMark() {
    return mark;
  }

  /** @param mark the mark to set */
  public void setMark(int mark) {
    this.mark = mark;
  }

  /** @return
   * @see gpl.scotlandyard.beans.basics.Node#getLinks() */
  public List<Link> getLinks() {
    return node.getLinks();
  }

  /** @return
   * @see gpl.scotlandyard.beans.basics.Node#getLocation() */
  public Point getLocation() {
    return node.getLocation();
  }

  /** @return
   * @see gpl.scotlandyard.beans.basics.Node#getNumber() */
  public int getNumber() {
    return node.getNumber();
  }

  /** @return
   * @see gpl.scotlandyard.beans.basics.Node#hashCode() */
  @Override
  public int hashCode() {
    return node.hashCode();
  }

  /** @param obj
   * @return
   * @see gpl.scotlandyard.beans.basics.Node#equals(java.lang.Object) */
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof MarkedNode) {
      return node.equals(((MarkedNode) obj).node);
    }
    return false;
  }

  /** @return */
  public Node getNode() {
    return node;
  }

  @Override
  public String toString() {
    return node.toString() + "[" + mark + "]";
  }

  /** @return */
  public static Comparator<MarkedNode> getNumberComparator() {
    return NUMBER_COMPARATOR;
  }

  /** @return */
  public static Comparator<MarkedNode> getMarkNumberComparator() {
    return MARK_COMPARATOR;
  }
}
